package org.fuys.coder.application;

import org.fuys.coder.common.constants.ResultMessageConstants;
import org.fuys.coder.common.entity.Result;
import org.fuys.coder.common.exception.BusinessException;
import org.fuys.coder.common.holder.UserHolder;
import org.fuys.coder.domain.user.model.req.operation.UserFollowReq;
import org.fuys.coder.domain.user.service.operation.IUserOperationService;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @projectName: fuys-low-coder
 * @package: org.fuys.coder.application
 * @className: UserOperationController
 * @author: WangJing
 * @description: 用户操作控制器 如关注,举报等
 * @date: 2024/7/28 21:44
 * @version: 1.0
 */

@RestController
@RequestMapping("/fuyscoder/user/operation")
public class UserOperationController {

    @Resource
    private IUserOperationService userOperationService;

    @PostMapping("/follow")
    public Result followAuthor(@RequestBody UserFollowReq followReq){
        if(ObjectUtils.isEmpty(followReq)){
            return Result.error(ResultMessageConstants.ILLEGAL_OPERATION);
        }
        if(ObjectUtils.isEmpty(followReq.getUserId())||
                ObjectUtils.isEmpty(followReq.getAuthorId())||ObjectUtils.isEmpty(followReq.getType())){
            return Result.error(ResultMessageConstants.ILLEGAL_DATA_FORMAT);
        }
        if(!followReq.getUserId().equals(UserHolder.get())){
            return Result.error(ResultMessageConstants.ILLEGAL_OPERATION);
        }
        try {
            String msg=ResultMessageConstants.FOLLOW_OK;
            boolean flag=userOperationService.followSomeOne(followReq);
            if(!flag){
                msg=ResultMessageConstants.CANCEL_FOLLOW;
            }
            return Result.ok().msg(msg);
        } catch (BusinessException e) {
            return Result.error(ResultMessageConstants.OPERATION_FAILED);
        }
    }


    @PostMapping("/report")
    public Result reportUser(){
        return Result.ok();
    }




}
